FIND block

Short summary

Name

FIND

→POU type

→function

Category

IEC-block, String

Conform to →IEC-standard

(error) currently restricted
(IEC demands data type ANY_STRING for the input IN1, hence the following data type is demanded as well: WSTRING. Currently, this data type is not supported for the block.
IEC demands data type ANY_CHARS for the input IN2, hence the following data types are demanded as well: WSTRINGCHARWCHAR. Currently, these data types are not supported for the block.) 

Graphical interface

Available since

version 1.30.0 (for Neuron Power Engineer)

Functionality

The block determines the first position where a partial strings begins within another string. Case sensitivity is of importance.

At input IN1, enter a string in which the searching is done (= 1st string). At input IN2, enter the string which is searched for (= 2nd string). If no occurrence of the value connected to IN2 is found, the block returns the value 0. If an empty character string is searched for, the block returns the value 1.

(info) Neuron Power Engineer  determines the character positions within a string as follows: 12, ..., n. 1 corresponds to the leftmost character position and n to the length of the string.
Three-character combination of the dollar sign ($) followed by two hexadecimal digits are evaluated as single character. Example: The string '$B15' (corresponds to '±5') consists of 2 characters. See →character string literal for more examples for those combinations. 

Inputs, return value

 

Identifier

→Data type

Description

Inputs:

IN1

STRING

1st input value (= string in which the searching is done)

 

IN2

STRING

2nd input value (= string which is searched for)

Return value:

USINTUINTUDINTULINTSINTINTDINT or LINT(corresponds to →generic data type ANY_INT

 

Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

See:

Example for usage within ST-editor

PROGRAM Test
    VAR
        result1, result2, result3, result4, result5, result6, result7 : INT;
        str6 : STRING[1];
    END_VAR
    result1 := FIND(IN1 := 'ASTRING_NEWSTRING', IN2 := 'STRING');     (* The variable 'result1' evaluates to '2'. *)
    result2 := FIND(IN1 := 'ASTRING_NEWSTRING', IN2 := 'String');     (* The variable 'result2' evaluates to '0'. Reason: The strings differ regarding their case sensitivity. *)
    result3 := FIND(IN1 := 'ASTRING_NEWSTRING', IN2 := 'NEW');        (* The variable 'result3' evaluates to '9'. *)
    result4 := FIND(IN1 := 'ASTRING_NEWSTRING', IN2 := 'X');          (* The variable 'result4' evaluates to '0'. *)
    result5 := FIND(IN1 := '$B15', IN2 := '5');                       (* The variable 'result5' evaluates to '2'. *)
    result6 := FIND(IN1 := 'ASTRING', IN2 := str6);                   (* The variable 'result6' evaluates to '1'. Reason: An empty string is searched for. *)
    result7 := FIND(IN1 := 'ASTRING', IN2 := '$00');                  (* The variable 'result7' evaluates to '1'. Reason: An empty string is searched for because '$00' is an empty string. *)
END_PROGRAM

When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.